﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using CardInChina.Bussiness.Frontend.Models;
using CardInChina.Bussiness.Frontend.Interface;
using CardInChina.Data.Entity.Entity;

namespace CardInChina.Web.Mvc.Controllers
{
    public class ExchangeController : CICBasicController
    {
        ExchangeBusinessService ebs = new ExchangeBusinessService();
        CardInfoBusinessService cbs = new CardInfoBusinessService();
        //
        // GET: /Exchange/
        public JsonResult GetCardsPriceInfo(CardInfoPriceRequestModel request)
        {
            CardInfoPriceResponseModel cpm = new CardInfoPriceResponseModel();
            cpm.CardInfoID = request.CardInfoID;
            foreach (var c in cbs.GetCardsFromCardInfoID(request.CardInfoID))
            {
                CardWithIDAndPrice cwidp = new CardWithIDAndPrice();
                cwidp.CardId = c.CardID;
                cwidp.CommomPrice = Math.Round(ebs.GetCommomPriceOfCardByExchange(c, request.CurrencyType),2);
                cwidp.VIPPrice = Math.Round(ebs.GetVIPPriceOfCardByExchange(c, request.CurrencyType),2);
                cpm.cardsPrice.Add(cwidp);
            }
            return Json(cpm);
        }

        public JsonResult GetCardPriceInfo(CardPriceRequestModel request)
        {
            CardPriceResponseModel cprm = new CardPriceResponseModel();
            cprm.CardId = request.CardID;
            cprm.CommomPrice = Math.Round(ebs.GetCommomPriceOfCardByExchange(request.CardID, request.CurrencyType), 2);
            cprm.VIPPrice = Math.Round(ebs.GetVIPPriceOfCardByExchange(request.CardID, request.CurrencyType), 2);
            return Json(cprm);
        }
    }
}
